"""
更新codesign上的icon的class name
"""
import re
from icon_r_util import get_icon_list_from_remote_in_codesign,update_icon_in_codesign, codesign_config


def update_icon_class_name(icon):
    replace_class_name_regex_str = codesign_config['replace_class_name_regex']
    # 根据正则表达式字符串创建正则表达式
    replace_class_name_regex = re.compile(replace_class_name_regex_str)
    # 获取icon的class name
    class_name = icon['class_name']
    # 执行正则表达式 获取匹配结果
    match_result = replace_class_name_regex.search(class_name)
    # 如果匹配结果为None 则表示没有匹配到
    if match_result is None:
        # 输出没有找到
        print('没有匹配到{}的class name'.format(class_name))
        return icon;
    # 获取匹配结果
    match_result = match_result.group()
    print(match_result)
    # 更新icon的class name
    icon['class_name'] = match_result
    update_icon_in_codesign(icon['id'],{
        'class_name': match_result
    })
    return icon


if __name__ == '__main__':


    icon_list = get_icon_list_from_remote_in_codesign()
    for icon in icon_list:
        update_icon_class_name(icon)
